package com.yuexunit.finance.thread;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import com.yuexunit.finance.common.util.DateUtils;
import com.yuexunit.finance.project.action.v1.FinanceApplicationActionApi;
import com.yuexunit.finance.project.action.v1.FinanceBulkstockActionApi;
import com.yuexunit.finance.project.action.v1.FinanceBulkstockPledgeActionApi;
import com.yuexunit.finance.project.action.v1.FinanceLoanActionApi;
import com.yuexunit.finance.project.action.v1.FinanceWorkbenchActionApi;
import com.yuexunit.finance.project.action.v1.WarningCenterActionApi;
import com.yuexunit.finance.project.action.v1.model.output.ContainerInventory;
import com.yuexunit.finance.project.action.v1.model.output.FinanceAuditDetail;
import com.yuexunit.finance.project.action.v1.model.output.FinanceLineInfo;
import com.yuexunit.finance.project.action.v1.model.output.LoanNoticeDetail;
import com.yuexunit.finance.project.action.v1.model.output.LoanNoticeLineInfo;
import com.yuexunit.finance.project.action.v1.model.output.PersonalWorkbench;
import com.yuexunit.finance.project.action.v1.model.output.PickupApplicationDetail;
import com.yuexunit.finance.project.action.v1.model.output.PickupApplicationLineInfo;
import com.yuexunit.finance.system.action.v1.dto.SendLetterMessage;
import com.yuexunit.inject.ComponentFactory;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;

public class FinanceThread extends Thread{
	private FinanceWorkbenchActionApi financeWorkbenchActionApi = ComponentFactory.loadClass(FinanceWorkbenchActionApi.class);
	private FinanceApplicationActionApi financeApplicationActionApi = ComponentFactory.loadClass(FinanceApplicationActionApi.class);
	private FinanceLoanActionApi financeLoanActionApi = ComponentFactory.loadClass(FinanceLoanActionApi.class);
	private FinanceBulkstockPledgeActionApi financeBulkstockPledgeActionApi = ComponentFactory.loadClass(FinanceBulkstockPledgeActionApi.class);
	private FinanceBulkstockActionApi financeBulkstockActionApi = ComponentFactory.loadClass(FinanceBulkstockActionApi.class);
	private WarningCenterActionApi warningCenterActionApi = ComponentFactory.loadClass(WarningCenterActionApi.class);
	
	private String warningTmp = "客户(%s)融资(%s)目前处于(%s)环节，审批即将超时，请及时处理！";
	private String agingTmp = "客户(%s)融资(%s)目前处于(%s)环节，审批已经超时，务必马上处理！";
	
	private String warningTmpApprove = "客户(%s)融资(%s)目前处于融资审批的(%s)环节，审批即将超时，请及时处理！";
	private String agingTmpApprove = "客户(%s)融资(%s)目前处于融资审批的(%s)环节，审批已经超时，务必马上处理！";
	
	private String warningTmpLoan = "客户(%s)融资(%s)目前处于放款审批的(%s)环节，审批即将超时，请及时处理！";
	private String agingTmpLoan = "客户(%s)融资(%s)目前处于放款审批的(%s)环节，审批已经超时，务必马上处理！";
	
	private String warningTmpPickup = "客户(%s)融资(%s)目前处于提货审批的(%s)环节，审批即将超时，请及时处理！";
	private String agingTmpPickup = "客户(%s)融资(%s)目前处于提货审批的(%s)环节，审批已经超时，务必马上处理！";
	
	public void run() {  
        while (!this.isInterrupted()) {// 线程未中断执行循环  
            try {  
                Thread.sleep(18000000); //每隔30分钟执行一次  
            } catch (InterruptedException e) {  
                e.printStackTrace();  
            }  
               
//           ------------------ 开始执行 ---------------------------  
            PersonalWorkbench pw = financeWorkbenchActionApi.personalWorkbench(Boolean.TRUE);
            PageCriteria pc = new PageCriteria(1, 100000);
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
          	//融资审批
            PageList<FinanceLineInfo> financeList1 = financeApplicationActionApi.inquireFinanceList(pw.getAudits().toArray(new Long[pw.getAudit()]), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, pc);
            for (FinanceLineInfo financeLineInfo : financeList1) {
				int difference = DateUtils.hoursBetween(financeLineInfo.getApplicationCreateDatetime(), DateUtils.now());
				sendMsg("financingApprove_1", difference, getWarningTime("applicationCreateDatetime"), getAgingTime("applicationCreateDatetime"), financeLineInfo.getEnterpriseName(), financeLineInfo.getFinanceNumber(), "融资审批");
				FinanceAuditDetail financeAudit = financeApplicationActionApi.inquireFinanceAuditDetail(financeLineInfo.getFinanceAuditId());
				try {
					if (financeAudit != null) {
						if (financeAudit.getBusinessAuditState() != null && financeAudit.getBusinessAuditState()) {
							if (financeAudit.getBusinessManageSubmitState() != null && financeAudit.getBusinessManageSubmitState()) {
								if (financeAudit.getRiskSubmitState() != null && financeAudit.getRiskSubmitState()) {
									if (financeAudit.getRiskMemberSubmitState() != null && financeAudit.getRiskMemberSubmitState()) {
										if (financeAudit.getOperationSubmitState() != null && financeAudit.getOperationSubmitState()) {
											if (financeAudit.getOperationManageSubmitState() != null && financeAudit.getOperationManageSubmitState()) {
												if (financeAudit.getFinancialSubmitState() != null && financeAudit.getFinancialSubmitState()) {
													if (financeAudit.getFinancialManageSubmitState() != null && financeAudit.getFinancialManageSubmitState()) {
														if (financeAudit.getCeoSubmitState() != null && financeAudit.getCeoSubmitState()) {
															difference = DateUtils.hoursBetween(dateFormat.parse(financeAudit.getCeoAuditDate()), DateUtils.now());
															sendMsg1("finalAudit_1", difference, getWarningTime("finalAudit"), getAgingTime("finalAudit"), financeLineInfo.getEnterpriseName(), financeLineInfo.getFinanceNumber(), "执行董事");
														} else {
															difference = DateUtils.hoursBetween(dateFormat.parse(financeAudit.getFinancialManageAuditDate()), DateUtils.now());
															sendMsg1("ceoAudit_1", difference, getWarningTime("ceoAudit"), getAgingTime("ceoAudit"), financeLineInfo.getEnterpriseName(), financeLineInfo.getFinanceNumber(), "总经理审核");
														}
													} else {
														difference = DateUtils.hoursBetween(dateFormat.parse(financeAudit.getFinancialAuditDate()), DateUtils.now());
														sendMsg1("financialManageAudit_1", difference, getWarningTime("financialManageAudit"), getAgingTime("financialManageAudit"), financeLineInfo.getEnterpriseName(), financeLineInfo.getFinanceNumber(), "资金领导审核");
													}
												} else {
													difference = DateUtils.hoursBetween(dateFormat.parse(financeAudit.getOperationManageAuditDate()), DateUtils.now());
													sendMsg1("financialAudit_1", difference, getWarningTime("financialAudit"), getAgingTime("financialAudit"), financeLineInfo.getEnterpriseName(), financeLineInfo.getFinanceNumber(), "资金审核");
												}
											} else {
												difference = DateUtils.hoursBetween(dateFormat.parse(financeAudit.getOperationAuditDate()), DateUtils.now());
												sendMsg1("operationManageAudit_1", difference, getWarningTime("operationManageAudit"), getAgingTime("operationManageAudit"), financeLineInfo.getEnterpriseName(), financeLineInfo.getFinanceNumber(), "运营领导审核");
											}
										} else {
											difference = DateUtils.hoursBetween(dateFormat.parse(financeAudit.getRiskMemberAuditDate()), DateUtils.now());
											sendMsg1("operationAudit_1", difference, getWarningTime("operationAudit"), getAgingTime("operationAudit"), financeLineInfo.getEnterpriseName(), financeLineInfo.getFinanceNumber(), "运营审核");
										}
									} else {
										difference = DateUtils.hoursBetween(dateFormat.parse(financeAudit.getRiskAuditDate()), DateUtils.now());
										sendMsg1("riskMemberAudit_1", difference, getWarningTime("riskMemberAudit"), getAgingTime("riskMemberAudit"), financeLineInfo.getEnterpriseName(), financeLineInfo.getFinanceNumber(), "风控领导审核");
									}
								} else {
									difference = DateUtils.hoursBetween(dateFormat.parse(financeAudit.getBusinessManageAuditDate()), DateUtils.now());
									sendMsg1("riskAudit_1", difference, getWarningTime("riskAudit"), getAgingTime("riskAudit"), financeLineInfo.getEnterpriseName(), financeLineInfo.getFinanceNumber(), "风控审核");
								}
							} else {
								difference = DateUtils.hoursBetween(dateFormat.parse(financeAudit.getBusinessAuditDate()), DateUtils.now());
								sendMsg1("businessManageAudit_1", difference, getWarningTime("businessManageAudit"), getAgingTime("businessManageAudit"), financeLineInfo.getEnterpriseName(), financeLineInfo.getFinanceNumber(), "业务领导审核");
							}
						} else {
							difference = DateUtils.hoursBetween(financeLineInfo.getApplicationCreateDatetime(), DateUtils.now());
							sendMsg1("businessAudit_1", difference, getWarningTime("businessAudit"), getAgingTime("businessAudit"), financeLineInfo.getEnterpriseName(), financeLineInfo.getFinanceNumber(), "业务审核");
						}
					}
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}
            
            //合同上传
            PageList<FinanceLineInfo> financeList2 = financeApplicationActionApi.inquireFinanceList(pw.getContracts().toArray(new Long[pw.getContract()]), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, pc);
            for (FinanceLineInfo financeLineInfo : financeList2) {
            	int difference = DateUtils.hoursBetween(financeLineInfo.getConstractCreateDatetime(), DateUtils.now());
            	sendMsg("contractUnsign_1", difference, getWarningTime("constractCreateDatetime"), getAgingTime("constractCreateDatetime"), financeLineInfo.getEnterpriseName(), financeLineInfo.getFinanceNumber(), "合同上传");
			}
            
            //通知装货
            PageList<FinanceLineInfo> financeList3 = financeApplicationActionApi.inquireFinanceList(pw.getRecieves().toArray(new Long[pw.getRecieve()]), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, pc);
            for (FinanceLineInfo financeLineInfo : financeList3) {
            	int difference = DateUtils.hoursBetween(financeLineInfo.getReceiveCreateDatetime(), DateUtils.now());
            	sendMsg("noticeReceive_1", difference, getWarningTime("receiveCreateDatetime"), getAgingTime("receiveCreateDatetime"), financeLineInfo.getEnterpriseName(), financeLineInfo.getFinanceNumber(), "通知装货");
			}
            
            //确认监管
            PageList<FinanceLineInfo> financeList4 = financeApplicationActionApi.inquireFinanceList(pw.getSupervisions().toArray(new Long[pw.getSupervision()]), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, pc);
            for (FinanceLineInfo financeLineInfo : financeList4) {
            	int difference = DateUtils.hoursBetween(financeLineInfo.getSupervisionCreateDatetime(), DateUtils.now());
            	sendMsg("financeUnsupervise_1", difference, getWarningTime("supervisionCreateDatetime"), getAgingTime("supervisionCreateDatetime"), financeLineInfo.getEnterpriseName(), financeLineInfo.getFinanceNumber(), "确认监管");
			}
            
            //放款申请
            PageList<FinanceLineInfo> financeList5 = financeApplicationActionApi.inquireFinanceList(pw.getLoads().toArray(new Long[pw.getLoad()]), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, pc);
            for (FinanceLineInfo financeLineInfo : financeList5) {
            	int difference = DateUtils.hoursBetween(financeLineInfo.getLoanApplicationCreateDatetime(), DateUtils.now());
            	sendMsg("financeUnrelease_1", difference, getWarningTime("loanApplicationCreateDatetime"), getAgingTime("loanApplicationCreateDatetime"), financeLineInfo.getEnterpriseName(), financeLineInfo.getFinanceNumber(), "放款申请");
			}
            
            //放款审批
            PageList<LoanNoticeLineInfo> loanNoticeList = financeLoanActionApi.inquireLoanNoticePageList(null, null, null, null, null, null,null, null, 1, pc);
            for (LoanNoticeLineInfo loanNoticeLineInfo : loanNoticeList) {
            	int difference = DateUtils.hoursBetween(loanNoticeLineInfo.getCreateDateTime(), DateUtils.now());
            	sendMsg("financeUnloan_1", difference, getWarningTime("loanAuditCreateTime"), getAgingTime("loanAuditCreateTime"), loanNoticeLineInfo.getEnterpriseName(), loanNoticeLineInfo.getFinanceNumber(), "放款审批");
            	
            	LoanNoticeDetail detail = financeLoanActionApi.inquireLoanNoticeDetail(loanNoticeLineInfo.getLoanNoticeId());
            	if (detail.getAuditSubmitState1() != null && detail.getAuditSubmitState1()) {
            		if (detail.getAuditSubmitState2() != null && detail.getAuditSubmitState2()) {
            			if (detail.getBusinessAuditSubmitState() != null && detail.getBusinessAuditSubmitState()) {
            				if (detail.getOperationAuditSubmitState() !=null && detail.getOperationAuditSubmitState()) {
            					if (detail.getFinancialAuditSubmitState() && detail.getFinancialAuditSubmitState()) {
            						if (detail.getFinancialLeaderAuditSubmitState() != null && detail.getFinancialLeaderAuditSubmitState()) {
            							if (detail.getLeader2AuditSubmitState() != null && detail.getLeader2AuditSubmitState()) {
            								difference = DateUtils.hoursBetween(loanNoticeLineInfo.getLeader1AuditDate(), DateUtils.now());
            			                	sendMsg2("loanNoticeLeader1Audit_1", difference, getWarningTime("multistageAudit8"), getAgingTime("multistageAudit8"), loanNoticeLineInfo.getEnterpriseName(), loanNoticeLineInfo.getFinanceNumber(), "执行董事审核");
            							} else {
            								difference = DateUtils.hoursBetween(loanNoticeLineInfo.getFinancialLeaderAuditDate(), DateUtils.now());
            			                	sendMsg2("loanNoticeLeader2Audit_1", difference, getWarningTime("multistageAudit7"), getAgingTime("multistageAudit7"), loanNoticeLineInfo.getEnterpriseName(), loanNoticeLineInfo.getFinanceNumber(), "总经理审核");
            							}
            						} else {
            							difference = DateUtils.hoursBetween(loanNoticeLineInfo.getFinancialAuditDate(), DateUtils.now());
            		                	sendMsg2("loanNoticeFinancialLeagerAudit_1", difference, getWarningTime("multistageAudit6"), getAgingTime("multistageAudit6"), loanNoticeLineInfo.getEnterpriseName(), loanNoticeLineInfo.getFinanceNumber(), "资金领导审核");
            						}
            					} else {
            						difference = DateUtils.hoursBetween(loanNoticeLineInfo.getOperationAuditDate(), DateUtils.now());
            	                	sendMsg2("loanNoticeFinancialAudit_1", difference, getWarningTime("multistageAudit5"), getAgingTime("5"), loanNoticeLineInfo.getEnterpriseName(), loanNoticeLineInfo.getFinanceNumber(), "资金审核");
            					}
            				} else {
            					difference = DateUtils.hoursBetween(loanNoticeLineInfo.getBusinessAuditDate(), DateUtils.now());
                            	sendMsg2("loanNoticeOperationAudit_1", difference, getWarningTime("multistageAudit4"), getAgingTime("multistageAudit4"), loanNoticeLineInfo.getEnterpriseName(), loanNoticeLineInfo.getFinanceNumber(), "风控领导审核");
            				}
            			} else {
            				difference = DateUtils.hoursBetween(loanNoticeLineInfo.getAuditDate2(), DateUtils.now());
                        	sendMsg2("loanNoticeBusinessAudit_1", difference, getWarningTime("multistageAudit3"), getAgingTime("multistageAudit3"), loanNoticeLineInfo.getEnterpriseName(), loanNoticeLineInfo.getFinanceNumber(), "风控审核");
            			}
            		} else {
            			difference = DateUtils.hoursBetween(loanNoticeLineInfo.getAuditDate1(), DateUtils.now());
                    	sendMsg2("loanNoticeAudit2_1", difference, getWarningTime("multistageAudit2"), getAgingTime("multistageAudit2"), loanNoticeLineInfo.getEnterpriseName(), loanNoticeLineInfo.getFinanceNumber(), "运营领导审核");
            		}
            	} else{
            		difference = DateUtils.hoursBetween(loanNoticeLineInfo.getCreateDateTime(), DateUtils.now());
                	sendMsg2("loanNoticeAudit1_1", difference, getWarningTime("multistageAudit1"), getAgingTime("multistageAudit1"), loanNoticeLineInfo.getEnterpriseName(), loanNoticeLineInfo.getFinanceNumber(), "运营审核");
            	}
			}
            
            //通知运输
            PageList<FinanceLineInfo> financeList6 = financeApplicationActionApi.inquireFinanceList(pw.getTransports().toArray(new Long[pw.getTransport()]), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, pc);
            for (FinanceLineInfo financeLineInfo : financeList6) {
            	int difference = DateUtils.hoursBetween(financeLineInfo.getTransportNoticeCreateDatetime(), DateUtils.now());
            	sendMsg("financeUntransport_1", difference, getWarningTime("transportNoticeCreateDatetime"), getAgingTime("transportNoticeCreateDatetime"), financeLineInfo.getEnterpriseName(), financeLineInfo.getFinanceNumber(), "通知运输");
			}
            
            //提货审批
            PageList<PickupApplicationLineInfo> pickupList1 = financeBulkstockPledgeActionApi.inquireNormalPickupApplicationPageList(pw.getPickups().toArray(new Long[pw.getPickup()]),null, null, null, null, null, null, null, null, null, null,null,null,null, pc);
            for (PickupApplicationLineInfo pickupApplicationLineInfo : pickupList1) {
            	int difference = DateUtils.hoursBetween(pickupApplicationLineInfo.getPickupApplicationCreateDateTime(), DateUtils.now());
            	sendMsg("financePickupExam_1", difference, getWarningTime("pickupApplicationCreateDatetime"), getAgingTime("pickupApplicationCreateDatetime"), pickupApplicationLineInfo.getEnterpriseName(), pickupApplicationLineInfo.getFinanceNumber(), "提货审批");
            	
            	PickupApplicationDetail detail = financeBulkstockPledgeActionApi.inquireNormalPickupApplicationDetail(pickupApplicationLineInfo.getPickupId());
            	try {
					if (detail.getBusinessAuditSubmitState() != null && detail.getBusinessAuditSubmitState()) {
						if (detail.getAuditSubmitState1() != null && detail.getAuditSubmitState1()) {
							if (detail.getRiskAuditSubmitState() != null && detail.getRiskAuditSubmitState()) {
								if (detail.getRiskMemberAuditSubmitState() != null && detail.getRiskMemberAuditSubmitState()) {
									if (detail.getFinancialAuditSubmitState() != null && detail.getFinancialAuditSubmitState()) {
										if (detail.getOperationAuditSubmitState() != null && detail.getOperationAuditSubmitState()) {
											if (detail.getCeoAuditSubmitState() != null && detail.getCeoAuditSubmitState()) {
												difference = DateUtils.hoursBetween(dateFormat.parse(detail.getCeoAuditDate()), DateUtils.now());
								            	sendMsg3("pickupConsentFinalAudit_1", difference, getWarningTime("finalAudit1"), getAgingTime("finalAudit1"), pickupApplicationLineInfo.getEnterpriseName(), pickupApplicationLineInfo.getFinanceNumber(), "执行董事审核");
											} else {
												difference = DateUtils.hoursBetween(dateFormat.parse(detail.getOperationAuditDate()), DateUtils.now());
								            	sendMsg3("pickupConsentCeoAudit_1", difference, getWarningTime("ceoAudit1"), getAgingTime("ceoAudit1"), pickupApplicationLineInfo.getEnterpriseName(), pickupApplicationLineInfo.getFinanceNumber(), "总经理审核");
											}
										} else {
											difference = DateUtils.hoursBetween(dateFormat.parse(detail.getFinancialAuditDate()), DateUtils.now());
							            	sendMsg3("pickupConsentOperationAudit_1", difference, getWarningTime("operationAudit1"), getAgingTime("operationAudit1"), pickupApplicationLineInfo.getEnterpriseName(), pickupApplicationLineInfo.getFinanceNumber(), "风控领导审核");
										}
									} else {
										difference = DateUtils.hoursBetween(dateFormat.parse(detail.getRiskMemberAuditDate()), DateUtils.now());
						            	sendMsg3("pickupConsentFinancialAudit_1", difference, getWarningTime("financialAudit1"), getAgingTime("financialAudit1"), pickupApplicationLineInfo.getEnterpriseName(), pickupApplicationLineInfo.getFinanceNumber(), "风控审核");
									}
								} else {
									difference = DateUtils.hoursBetween(dateFormat.parse(detail.getRiskAuditDate()), DateUtils.now());
					            	sendMsg3("pickupConsentRiskMemberAudit_1", difference, getWarningTime("riskMemberAudit1"), getAgingTime("riskMemberAudit1"), pickupApplicationLineInfo.getEnterpriseName(), pickupApplicationLineInfo.getFinanceNumber(), "资金领导审核");
								}
							} else {
								difference = DateUtils.hoursBetween(dateFormat.parse(detail.getAuditDate1()), DateUtils.now());
					        	sendMsg3("pickupConsentRiskAudit_1", difference, getWarningTime("riskAudit1"), getAgingTime("riskAudit1"), pickupApplicationLineInfo.getEnterpriseName(), pickupApplicationLineInfo.getFinanceNumber(), "资金审核");
							}
						} else {
							difference = DateUtils.hoursBetween(dateFormat.parse(detail.getBusinessAuditDate()), DateUtils.now());
					    	sendMsg3("pickupConsentAudit1_1", difference, getWarningTime("audit11"), getAgingTime("audit11"), pickupApplicationLineInfo.getEnterpriseName(), pickupApplicationLineInfo.getFinanceNumber(), "运营领导审核");
						}
					} else {
						difference = DateUtils.hoursBetween(detail.getPickupApplicationCreateDateTime(), DateUtils.now());
						sendMsg3("pickupConsentBusinessAudit_1", difference, getWarningTime("businessAudit1"), getAgingTime("businessAudit1"), pickupApplicationLineInfo.getEnterpriseName(), pickupApplicationLineInfo.getFinanceNumber(), "运营审核");
					}
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}
            
            //收款确认
            PageList<PickupApplicationLineInfo> pickupList2 = financeWorkbenchActionApi.inquireWaitReceivablesPickupApplicationPageList(pw.getReceivableses().toArray(new Long[pw.getReceivables()]),null,null,null,null, pc);
            for (PickupApplicationLineInfo pickupApplicationLineInfo : pickupList2) {
            	int difference = DateUtils.hoursBetween(pickupApplicationLineInfo.getReceiveConfirmCreateDateTime(), DateUtils.now());
            	sendMsg("financeUntransport_1", difference, getWarningTime("receiveConfirmCreateDatetime"), getAgingTime("receiveConfirmCreateDatetime"), pickupApplicationLineInfo.getEnterpriseName(), pickupApplicationLineInfo.getFinanceNumber(), "收款确认");
			}
            
            //放货通知
            PageList<PickupApplicationLineInfo> pickupList3 = financeWorkbenchActionApi.inquireWaitDeliveryPickupApplicationPageList(pw.getDeliveries().toArray(new Long[pw.getDelivery()]), null, null, null,null,null,null, pc);
            for (PickupApplicationLineInfo pickupApplicationLineInfo : pickupList3) {
            	int difference = DateUtils.hoursBetween(pickupApplicationLineInfo.getDeliveryNoticeCreateDateTime(), DateUtils.now());
            	sendMsg("financeUntransport_1", difference, getWarningTime("deliveryNoticeCreateDatetime"), getAgingTime("deliveryNoticeCreateDatetime"), pickupApplicationLineInfo.getEnterpriseName(), pickupApplicationLineInfo.getFinanceNumber(), "放货通知");
			}
            
            //解除监管
            PageList<ContainerInventory> inventoryList = financeBulkstockActionApi.inquireBulkstockInventoryPageList(null, null, pw.getRelieves().toArray(new Long[pw.getRelieve()]), null, null, null, null, null, null, null, null,null, pc);
            for (ContainerInventory containerInventory : inventoryList) {
            	int difference = DateUtils.hoursBetween(containerInventory.getSupervisionRelieveCreateTime(), DateUtils.now());
            	sendMsg("financeUntransport_1", difference, getWarningTime("supervisionRelieveCreateDatetime"), getAgingTime("supervisionRelieveCreateDatetime"), containerInventory.getEnterpriseName(), containerInventory.getFinanceNumber(), "解除监管");
			}
        }  
    } 
	
	private void sendMsg(String permissionId, int difference, int warningTime, int agingTime, String enterpriseName, String financeNumber, String link) {
		if (difference >= warningTime && difference < agingTime) {
			SendLetterMessage.sendLetterMessage(permissionId, String.format(warningTmp, enterpriseName, financeNumber, link));
		} else if (difference > agingTime) {
			SendLetterMessage.sendLetterMessage(permissionId, String.format(agingTmp, enterpriseName, financeNumber, link));
		}
	}
	
	//融资审批消息提醒
	private void sendMsg1(String permissionId, int difference, int warningTime, int agingTime, String enterpriseName, String financeNumber, String link) {
		if (difference >= warningTime && difference < agingTime) {
			SendLetterMessage.sendLetterMessage(permissionId, String.format(warningTmpLoan, enterpriseName, financeNumber, link));
		} else if (difference > agingTime) {
			SendLetterMessage.sendLetterMessage(permissionId, String.format(agingTmpLoan, enterpriseName, financeNumber, link));
		}
	}
	
	//放款审批消息提醒
	private void sendMsg2(String permissionId, int difference, int warningTime, int agingTime, String enterpriseName, String financeNumber, String link) {
		if (difference >= warningTime && difference < agingTime) {
			SendLetterMessage.sendLetterMessage(permissionId, String.format(warningTmpApprove, enterpriseName, financeNumber, link));
		} else if (difference > agingTime) {
			SendLetterMessage.sendLetterMessage(permissionId, String.format(agingTmpApprove, enterpriseName, financeNumber, link));
		}
	}
	
	//提货审批消息提醒
	private void sendMsg3(String permissionId, int difference, int warningTime, int agingTime, String enterpriseName, String financeNumber, String link) {
		if (difference >= warningTime && difference < agingTime) {
			SendLetterMessage.sendLetterMessage(permissionId, String.format(warningTmpPickup, enterpriseName, financeNumber, link));
		} else if (difference > agingTime) {
			SendLetterMessage.sendLetterMessage(permissionId, String.format(agingTmpPickup, enterpriseName, financeNumber, link));
		}
	}
	
	private int getWarningTime(String auditWarningId){
		return warningCenterActionApi.inquireAuditWarning(auditWarningId).getWarningTime();
	}
	
	private int getAgingTime(String auditWarningId){
		return warningCenterActionApi.inquireAuditWarning(auditWarningId).getAgingTime();
	}
}
